// https://github.com/nimojs/gulp-book
var gulp = require('gulp');
var rename = require('gulp-rename');
var htmlReplace = require('gulp-html-replace');
const c = require('ansi-colors');
var log = require('fancy-log');
var pkg = require('./package');

gulp.task('rename', function () {
	gulp.src('index.html')
		.pipe(rename({
				basename:'JSON 格式化工具',
				suffix: 'v' + pkg.version,
				extname: '.hta'
			}))
		.pipe(htmlReplace({ver: pkg.version }))
		.pipe(gulp.dest('dist/'));
});

gulp.task('watch', function () {
	gulp.watch('index.html', function (event) {
		var path = event.path;
		log(c.green(event.type) + ' ' + path);
		gulp.src(path)
			.pipe(rename({
				suffix: 'v' + pkg.version,
				extname: '.hta'
			}))
			.pipe(htmlReplace({ver: pkg.version }))
			.pipe(gulp.dest('dist/'));
	});
});

// 使用 gulp.task('default') 定义默认任务
gulp.task('default', ['rename']);